package com.qianfeng.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.qianfeng.ssm.dto.Result;
import com.qianfeng.ssm.pojo.Person;
import com.qianfeng.ssm.pojo.Person;
import com.qianfeng.ssm.service.PersonService;
import com.qianfeng.ssm.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Zhao_Win
 * @version V1.0
 * @Project AllDay
 * @Date 2022/3/10 16:08
 */

@RestController
@RequestMapping("/test")
public class PersonController {

    private PersonService personService;

    @Autowired
    public void setpersonService(PersonService personService){
        this.personService = personService;
    }


    @GetMapping("/test1/{id}")
    public Result findById(@PathVariable Long id){
        Person byId = personService.findById(id);
        return Result.setOk(byId);
    }

    @GetMapping("/test2")
    public Result findAll(@RequestParam(defaultValue = "2")int pageSize,@RequestParam(defaultValue = "1")int pageNum){
        PageInfo<Person> personPageInfo = personService.findAll(pageSize, pageNum);
        return Result.setOk(personPageInfo);
    }

    @PostMapping("/test3")
    public Result addperson(@RequestBody Person person){
        int i = personService.addPerson(person);
        return Result.setOk();

    }

    @GetMapping("/test/{id}")
    public Result deleteperson(@PathVariable Long id){
        personService.deletePerson(id);
        return Result.setOk();
    }

    @GetMapping("/updata")
    public Result updatepersonById(){
        personService.updatePersonById(new Person());
        return Result.setOk();
    }

}
